﻿using System.Collections.Generic;

namespace Fish.Utility
{
	public class TakePool
	{
		private IDictionary<string, EventlineTake> takeDic = new Dictionary<string, EventlineTake>();

		public EventlineTake this[string path]
		{
			get
			{
				return Get(path);
			}
		}

		private TakePool() { }

		public static TakePool Create()
		{
			return new TakePool();
		}

		private EventlineTake Get(string path)
		{
			EventlineTake take;

			if (takeDic.TryGetValue(path, out take))
				return take;

			return Register(path);
		}

		private EventlineTake Register(string path)
		{
			var take = Eventline.LoadTake(path);

			takeDic.Add(path, take);

			return take;
		}
	}
}
